<template>
  <div id = 'process-flow'>
    <!-- {{currentData}} -->
    <div class="detail-wrap">
      <div class = 'process-flow__operation'>
         <div>
           <label class="label-text">流程名称</label>
           <el-input size="mini"  v-model.trim="currentData.DisplayName" auto-complete="off" :disabled="false"></el-input>
         </div>
         <div class = 'process-poeration__start'>
           <label class="label-text">开始节点</label>
           <div>
           <el-select size="mini" v-model="currentData.FirstNodeType" :placeholder="$t('public.pleasePick')" :disabled="false" class="select" @change = 'firstTypeChange'>
              <el-option
                v-for="item in toPeerTypeArr"
                :key="item.TypeValue"
                :label="item.TypeName"
                :value="item.TypeValue"
              >
              </el-option>
            </el-select>
            <span>——</span>
            <el-select v-if="showSelect === 'agent'" size="mini" v-model="currentData.FirstNode" :placeholder="$t('public.pleasePick')" :disabled="false" class="select" @change = 'firstNodeChange'>
              <el-option
                v-for="item in FirstNodeArr"
                :key="item._id"
                :label="item.displayName"
                :value="item._id"
                >
              </el-option>
            </el-select>
            <el-select v-if="showSelect === 'system' || showSelect === 'others'" size="mini" v-model="currentData.FirstNode" :placeholder="$t('public.pleasePick')" :disabled="false" class="select" @change = 'firstNodeChange'>
              <el-option
                v-for="item in FirstNodeArr"
                :key="item.Exten"
                :label="item.DisplayName"
                :value="item.Exten"
                >
              </el-option>
            </el-select>
            </div>
         </div>
         <div class = 'process-poeration__btn'>
            <el-button class="primary_btn" @click = 'prcessNodeCancel'>取消</el-button>
            <el-button type="primary" class="primary_btn" @click = 'prcessNodeSave'>保存</el-button>
            <el-button class = 'save_btn' :disabled = 'toolsDisable' @click = 'active'>生效</el-button>
         </div>
      </div>
      <div class = 'process-flow__title'>
         <div class = 'process-flow-title__text'>
           流程图
         </div>
         <el-dropdown  split-button size="small" type="primary" @command="addFirstNodeClick" placement='bottom-start' trigger="click">
            新增节点
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-for="item in newToPeerTypeArr" :command = 'item'>{{item.TypeName}}</el-dropdown-item>
            </el-dropdown-menu>
         </el-dropdown>
         <el-button class="primary_btn" size='small' @click.stop="enlarge">放大</el-button>
      </div>
      <div v-show="chartError" class="error font16">
        流程图绘制出错，请检查流程配置是否有误
      </div>
      <div class="svgContainer" v-show="!chartError">
        <div id="process-flow__view">
        </div>
      </div>
      <div class="icon-group">
        <span><i class="fa fa-volume-up" aria-hidden="true"></i>：播放语音节点</span>
        <span><i class="fa fa-file-audio-o" aria-hidden="true"></i>：播放文本节点</span>
        <span><i class="fa fa-building-o" aria-hidden="true"></i>：按键菜单节点</span>
        <span><i class="fa fa-files-o" aria-hidden="true"></i>：赋值节点</span>
        <span><i class="fa fa-volume-control-phone" aria-hidden="true"></i>：CallUrl节点</span>
        <span><i class="fa fa-clock-o" aria-hidden="true"></i>：{{$t('configLazyLoad.process.node8')}}</span>
        <span><i class="fa fa-envelope-o" aria-hidden="true"></i>：留言节点</span>
        <span><i class="fa fa-home" aria-hidden="true"></i>：会议室节点</span>
        <span><i class="fa fa-heartbeat" aria-hidden="true"></i>：自定义满意度节点</span>
        <span><i class="fa fa-retweet" aria-hidden="true"></i>：采集输入节点</span>
        <span><i class="fa fa-shield" aria-hidden="true"></i>：MD5加密节点</span>
        <span><i class="fa fa-random" aria-hidden="true"></i>：按变量路由节点</span>
        <span><i class="fa fa-tags" aria-hidden="true"></i>：自定义节点</span>
        <span><i class="fa fa-phone" aria-hidden="true"></i>：采集工号并拨打节点</span>
        <span><i class="fa fa-deaf" aria-hidden="true"></i>：转IVR菜单节点</span>
        <span><i class="fa fa-lock" aria-hidden="true"></i>：系统节点-挂机</span>
        <span><i class="fa fa-heart" aria-hidden="true"></i>：系统节点-满意度调查</span>
        <span><i class="fa fa-phone" aria-hidden="true"></i>：系统节点-拨打工号</span>
        <span><i class="fa fa-exchange" aria-hidden="true"></i>：双向回呼节点</span>
        <span><i class="fa fa-microphone" aria-hidden="true"></i>：语言识别节点</span>
        <span><i class="fa fa-users" aria-hidden="true"></i>：技能组</span>
        <span><i class="fa fa-user" aria-hidden="true"></i>：座席</span>
      </div>
    </div>
  </div>
</template>
<script>
  import mermaid from 'mermaid'
//  import 'mermaid/dist/mermaid.forest.css'
  import 'font-awesome/css/font-awesome.css'
  import { deepClone } from '@/utils/m7Utils'
  export default {
    name: 'processFlow',
    data () {
      let self = this
      window.nodeClick = function (item) {
        self.handlerNodeClick(this.id)
      }
      return {
        name: 'pcocessConfig',
        toolsDisable: true,
        chartError: false,
        textCode: '',
        textLength: 0,
        newFirstNode: '',
        FirstNodeArr: [],
        showSelect: 'others',
        toPeerTypeArr: [
          {TypeValue: 'system', TypeName: this.$t('configLazyLoad.process.node')},
          {TypeValue: 'ivr_node_queue', TypeName: '技能组'},
          {TypeValue: 'account_user', TypeName: '座席'},
          {TypeValue: 'ivr_node_announcement', TypeName: '播放语音节点'},
          {TypeValue: 'ivr_node_text_announcement', TypeName: '播放文本语音节点'},
          {TypeValue: 'ivr_node_ivr', TypeName: '按键菜单节点'},
          {TypeValue: 'ivr_node_encrypt_md5', TypeName: 'MD5加密节点'},
          {TypeValue: 'ivr_node_validation', TypeName: '采集输入节点'},
          {TypeValue: 'ivr_node_assignment', TypeName: '赋值节点'},
          {TypeValue: 'ivr_node_route', TypeName: '按变量路由节点'},
          {TypeValue: 'ivr_node_ivr_menu', TypeName: '转IVR菜单节点'},
          {TypeValue: 'ivr_node_call_url', TypeName: 'CallUrl节点'},
          {TypeValue: 'ivr_node_date', TypeName: this.$t('configLazyLoad.process.node8')},
          {TypeValue: 'ivr_node_twowaycall', TypeName: '双向回呼节点'},
          {TypeValue: 'ivr_node_asr', TypeName: '语音识别节点'},
          {TypeValue: 'ivr_node_voice_mail', TypeName: '留言节点'},
          {TypeValue: 'ivr_node_room', TypeName: '会议室节点'},
          {TypeValue: 'ivr_node_satisfaction', TypeName: '自定义满意度节点'},
          {TypeValue: 'ivr_node_superDialJobNum', TypeName: '采集工号并拨打节点'},
          {TypeValue: 'ivr_node_extension_peer', TypeName: '自定义节点'}
        ],
        newToPeerTypeArr: [
          {TypeValue: 'ivr_node_announcement', TypeName: '播放语音节点'},
          {TypeValue: 'ivr_node_text_announcement', TypeName: '播放文本语音节点'},
          {TypeValue: 'ivr_node_ivr', TypeName: '按键菜单节点'},
          {TypeValue: 'ivr_node_encrypt_md5', TypeName: 'MD5加密节点'},
          {TypeValue: 'ivr_node_validation', TypeName: '采集输入节点'},
          {TypeValue: 'ivr_node_assignment', TypeName: '赋值节点'},
          {TypeValue: 'ivr_node_route', TypeName: '按变量路由节点'},
          {TypeValue: 'ivr_node_ivr_menu', TypeName: '转IVR菜单节点'},
          {TypeValue: 'ivr_node_call_url', TypeName: 'CallUrl节点'},
          {TypeValue: 'ivr_node_date', TypeName: this.$t('configLazyLoad.process.node8')},
          {TypeValue: 'ivr_node_twowaycall', TypeName: '双向回呼节点'},
          {TypeValue: 'ivr_node_asr', TypeName: '语音识别节点'},
          {TypeValue: 'ivr_node_voice_mail', TypeName: '留言节点'},
          {TypeValue: 'ivr_node_room', TypeName: '会议室节点'},
          {TypeValue: 'ivr_node_satisfaction', TypeName: '自定义满意度节点'},
          {TypeValue: 'ivr_node_superDialJobNum', TypeName: '采集工号并拨打节点'},
          {TypeValue: 'ivr_node_extension_peer', TypeName: '自定义节点'}
        ],
        nodeName2Alias: {
          ivr_node_announcement: 'A',
          ivr_node_text_announcement: 'B',
          ivr_node_ivr: 'C',
          ivr_node_validation: 'D',
          ivr_node_assignment: 'E',
          ivr_node_encrypt_md5: 'F',
          ivr_node_route: 'G',
          ivr_node_call_url: 'H',
          ivr_node_voice_mail: 'I',
          ivr_node_room: 'J',
          ivr_node_satisfaction: 'K',
          ivr_node_extension_peer: 'L',
          ivr_node_superDialJobNum: 'M',
          ivr_node_ivr_menu: 'N',
          system: {
            0: 'O1', // 挂机
            1: 'O2', // 满意度调查
            2: 'O3'  // 拨打工号
          },
          ivr_node_system: 'O3',
          ivr_node_queue: 'P',
          account_user: 'Q',
          ivr_node_twowaycall: 'R',
          ivr_node_asr: 'S',
          ivr_node_date: 'T'
        },
        nodeType2Font: {
          ivr_node_announcement: 'fa:fa-volume-up',
          ivr_node_text_announcement: 'fa:fa-file-audio-o',
          ivr_node_ivr: 'fa:fa-building-o',
          ivr_node_validation: 'fa:fa-retweet',
          ivr_node_assignment: 'fa:fa-files-o',
          ivr_node_encrypt_md5: 'fa:fa-shield',
          ivr_node_route: 'fa:fa-random',
          ivr_node_call_url: 'fa:fa-volume-control-phone',
          ivr_node_voice_mail: 'fa:fa-envelope-o',
          ivr_node_room: 'fa:fa-home',
          ivr_node_satisfaction: 'fa:fa-heartbeat',
          ivr_node_extension_peer: 'fa:fa-tags',
          ivr_node_superDialJobNum: 'fa:fa-phone',
          ivr_node_ivr_menu: 'fa:fa-deaf',
          ivr_node_system: 'fa:fa-phone',
          ivr_node_queue: 'fa:fa-users',
          account_user: 'fa:fa-user',
          system: {
            0: 'fa:fa-lock', // 挂机
            1: 'fa:fa-heart', // 满意度调查
            2: 'fa:fa-phone'  // 拨打工号
          },
          ivr_node_twowaycall: 'fa:fa-exchange',
          ivr_node_asr: 'fa:fa-microphone',
          ivr_node_date: 'fa:fa-clock-o'
        },
        nodeName2ChineseName: {
          ivr_node_announcement: '播放语音节点',
          ivr_node_text_announcement: '播放文本节点',
          ivr_node_ivr: '按键菜单节点',
          ivr_node_validation: '采集输入节点',
          ivr_node_assignment: '赋值节点',
          ivr_node_encrypt_md5: 'MD5加密节点',
          ivr_node_route: '按变量路由节点',
          ivr_node_call_url: 'CallUrl节点',
          ivr_node_voice_mail: '留言节点',
          ivr_node_room: '会议室节点',
          ivr_node_satisfaction: '自定义满意度节点',
          ivr_node_extension_peer: '自定义节点',
          ivr_node_superDialJobNum: '采集工号并拨打节点',
          ivr_node_ivr_menu: '转IVR菜单节点',
          system: {
            0: '挂机', // 挂机
            1: '满意度调查', // 满意度调查
            2: '拨打工号'  // 拨打工号
          },
          ivr_node_system: '拨打工号',
          ivr_node_queue: '技能组',
          account_user: '座席',
          ivr_node_twowaycall: '双向回呼节点',
          ivr_node_asr: '语音识别节点',
          ivr_node_date: '时间节点'
        },
        node2PeerCondition: {
          ivr_node_announcement: 'next',
          ivr_node_text_announcement: 'next',
          ivr_node_validation: {
            ToPeerType: '成功',
            ToPeerTypeWhenWaitTimeout: '超时'
          },
          ivr_node_assignment: 'next',
          ivr_node_encrypt_md5: 'next',
          ivr_node_route: {
            ToPeerType: '满足条件',
            ToPeerTypeUnmatched: '不满足条件'
          },
          ivr_node_call_url: {
            NextPeerType: '成功',
            ToPeerTypeWhenTimeout: '超时'
          },
          ivr_node_voice_mail: 'next',
          ivr_node_satisfaction: 'next',
          ivr_node_superDialJobNum: {
            ToPeerTypeWhenFrontOffice: '按0前台转向',
            ToPeerTypeWhenEmpnoNotExist: '工号不存在',
            ToPeerTypeWhenEmpnoAgentBusy: '座席忙',
            ToPeerTypeWhenEmpnoLogoff: '网关未注册也未绑定手机'
          },
          ivr_node_ivr_menu: 'next',
          ivr_node_system: {
            ToPeerTypeWhenEmpnoNotExist: '工号不存在',
            ToPeerTypeWhenEmpnoAgentBusy: '座席忙',
            ToPeerTypeWhenEmpnoLogoff: '座席未登录'
          },
          ivr_node_queue: {
            ToPeerTypeWhenQueueEmpty: '技能组为空时',
            ToPeerTypeWhenWait: '正在等待时',
            ToPeerTypeWhenWaitTimeout: '等待超时',
            ToPeerTypeWhenHanguped: '通话结束'
          },
          ivr_node_date: {
            NextPeerUnmatch: '不满足条件',
            NextPeer: '时间满足条件',
            Order: '优先级'
          }
        },
        systemPeerTypeArr: [
          {name: '挂机', value: '0'},
          {name: '满意度调查', value: '1'},
          {name: '拨工号', value: '2'}
        ],
        vars: {},
        aliasNodeType: {
          A: {
            type: 'ivr_node_announcement',
            component: 'ivrNodeAnnouncement'
          },
          B: {
            type: 'ivr_node_text_announcement',
            component: 'ivrNodeTextAnnouncement'
          },
          C: {
            type: 'ivr_node_ivr',
            component: 'ivrNodeIvr',
            width: '500px'
          },
          D: {
            type: 'ivr_node_validation',
            component: 'ivrNodeValidation'
          },
          E: {
            type: 'ivr_node_assignment',
            component: 'ivrNodeAssignment'
          },
          F: {
            type: 'ivr_node_encrypt_md5',
            component: 'ivrNodeEncryptMd5'
          },
          G: {
            type: 'ivr_node_route',
            component: 'ivrNodeRoute',
            width: '700px'
          },
          H: {
            type: 'ivr_node_call_url',
            component: 'ivrNodeCallUrl'
          },
          I: {
            type: 'ivr_node_voice_mail',
            component: 'ivrNodeVoiceMail'
          },
          J: {
            type: 'ivr_node_room',
            component: 'ivrNodeRoom'
          },
          K: {
            type: 'ivr_node_satisfaction',
            component: 'ivrNodeSatisfaction'
          },
          L: {
            type: 'ivr_node_extension_peer',
            component: 'ivrNodeExtensionPeer'
          },
          M: {
            type: 'ivr_node_superDialJobNum',
            component: 'ivrNodeSuperDialJobNum'
          },
          N: {
            type: 'ivr_node_ivr_menu',
            component: 'ivrNodeIvrMenu'
          },
          O: {
            type: 'ivr_node_system',
            component: 'ivrNodeSystem'
          },
          P: {
            type: 'ivr_node_queue',
            component: 'ivrNodeQueue'
          },
          R: {
            type: 'ivr_node_twowaycall',
            component: 'ivrNodeTwowaycall'
          },
          S: {
            type: 'ivr_node_asr',
            component: 'ivrNodeAsr'
          },
          T: {
            type: 'ivr_node_date',
            component: 'ivrNodeDate',
            width: '1000px'
          }
        },
        currentData: this.flowData,
        ccount: 0,
        nodeInitObj: {
          ivr_node_announcement: {
            data: {
              _id: '',
              DisplayName: '',
              Filename: '',
              NotBreak: false,
              ToPeerType: '',
              ToPeer: ''
            },
            component: 'ivrNodeAnnouncement'
          },
          ivr_node_text_announcement: {
            data: {
              _id: '',
              DisplayName: '',
              Engine: '',
              AnnouncementText: '',
              MrcpVar: '',
              ReplaceVar: '',
              VoiceName: '',
              Speed: '',
              Pitch: '',
              Volume: '',
              WordInterval: '',
              SignInterval: '',
              IsMoney: '',
              ToPeerType: '',
              ToPeer: ''
            },
            component: 'ivrNodeTextAnnouncement'
          },
          ivr_node_ivr: {
            data: {
              _id: '',
              Exten: '',
              DisplayName: '',
              Timeout: '10',
              Filename: '',
              IvrKeys: []
            },
            component: 'ivrNodeIvr',
            width: '500px'
          },
          ivr_node_validation: {
            data: {
              DisplayName: '',
              Filename: '',
              EndType: '1',
              Data: '',
              EndKey: '#',
              Min: '1',
              Max: '30',
              EndLength: '4',
              WaitTime: '20',
              ReturnKey: '#',
              ToPeerTypeWhenWaitTimeout: '',
              ToPeerWhenWaitTimeout: '',
              ToPeerType: '',
              ToPeer: '',
              _id: ''
            },
            component: 'ivrNodeValidation'
          },
          ivr_node_assignment: {
            data: {
              DisplayName: '',
              VarConditions: [],
              ToPeerType: '',
              ToPeer: ''
            },
            component: 'ivrNodeAssignment'
          },
          ivr_node_encrypt_md5: {
            data: {
              _id: '',
              Exten: '',
              DisplayName: '',
              EncryptText: '',
              Variable: '',
              NextPeerType: '',
              NextPeer: ''
            },
            component: 'ivrNodeEncryptMd5'
          },
          ivr_node_route: {
            data: {
              DisplayName: '',
              Routes: [],
              ToPeerTypeUnmatched: '',
              ToPeerUnmatched: '',
              ToPeerType: '',
              ToPeer: ''
            },
            component: 'ivrNodeRoute',
            width: '700px'
          },
          ivr_node_call_url: {
            data: {
              DisplayName: '',
              Filename: '',
              Url: '',
              MD5: '',
              Timeout: '10',
              Variable: '',
              NextPeerType: '',
              NextPeer: '',
              ToPeerTypeWhenTimeout: '',
              ToPeerWhenTimeout: '',
              _id: ''
            },
            component: 'ivrNodeCallUrl'
          },
          ivr_node_voice_mail: {
            data: {
              _id: '',
              DisplayName: '',
              Exten: '',
              ToPeerType: '',
              ToPeer: '',
              Filename: ''
            },
            component: 'ivrNodeVoiceMail'
          },
          ivr_node_room: {
            data: { _id: '', DisplayName: '', Exten: '', RoomPassword: '' },
            component: 'ivrNodeRoom'
          },
          ivr_node_satisfaction: {
            data: {
              _id: '',
              DisplayName: '',
              Exten: '',
              Welfilename: '',
              Invalidfilename: '',
              Timeoutfilename: '',
              Byefilename: '',
              Endfilename: '',
              Data: '',
              NextPeerType: '',
              NextPeer: ''
            },
            component: 'ivrNodeSatisfaction'
          },
          ivr_node_extension_peer: {
            data: { _id: '', DisplayName: '', Exten: '', DialPlan: '' },
            component: 'ivrNodeExtensionPeer'
          },
          ivr_node_superDialJobNum: {
            data: {
              _id: '',
              DisplayName: '',
              Exten: '',
              Filename: '',
              ToPeerTypeWhenFrontOffice: '', // 按0前台转向
              ToPeerWhenFrontOffice: '',
              ToPeerTypeWhenEmpnoNotExist: '', // 工号不存在转向
              ToPeerWhenEmpnoNotExist: '',
              ToPeerTypeWhenEmpnoAgentBusy: '', // 座席忙转向
              ToPeerWhenEmpnoAgentBusy: '',
              ToPeerTypeWhenEmpnoLogoff: '', // 网关未注册也未绑定手机转向
              ToPeerWhenEmpnoLogoff: ''
            },
            component: 'ivrNodeSuperDialJobNum'
          },
          ivr_node_ivr_menu: {
            data: {
              _id: '',
              DisplayName: '',
              MenuType: 'inner',
              NextPeerType: '',
              NextPeer: '',
              MenuOutNum: ''
            },
            component: 'ivrNodeIvrMenu'
          },
          ivr_node_system: {
            data: { type: 'ivr_node_system', component: 'ivrNodeSystem' },
            component: 'ivrNodeSystem'
          },
          ivr_node_queue: {
            data: {},
            component: 'ivrNodeQueue'
          },
          ivr_node_twowaycall: {
            data: { _id: '', DisplayName: '', Filename: '', Variable: '' },
            component: 'ivrNodeTwowaycall'
          },
          ivr_node_asr: {
            data: {
              _id: '',
              DisplayName: '',
              Exten: '',
              Type: 'normal', // 播报的文本
              PreVoice: '', // 录音前提示音
              StopSignal: '', // 终止语音识别按键
              SilenceTime: '', // 沉默时间
              Variable: '', // 返回结果赋值变量
              EndRobotKey: '', // 终止机器人问答关键字
              IsRobotHandle: false, // 是否交给机器人处理
              NextPeerType: '', // 识别后转向类型
              NextPeer: '', // 识别后转向值
              Vocab_id: '' // 热词
            },
            component: 'ivrNodeAsr'
          },
          ivr_node_date: {
            data: {
              DisplayName: '',
              Dates: [],
              ToPeerTypeUnmatched: '',
              ToPeerUnmatched: '',
              ToPeerType: '',
              ToPeer: ''
            },
            component: 'ivrNodeDate',
            width: '1000px'
          }
        }
      }
    },
    computed: {
      currentPBX () {
        return this.$store.state.config.callCenter.currentPBX
      }
    },
    props: {
      showBread: String,
      flowData: {
        type: Object,
        default: function () {
          return {}
        }
      },
      isUpdateProcessView: {type: Number, default: 0},
      isUpdateFirstNode: {type: Number, default: 0},
      processViewShow: {type: Boolean, default: false}
    },
    methods: {
      addFirstNodeClick (obj) {
        let nodeType = obj.TypeValue
        let nodeName = this.nodeName2ChineseName[nodeType]
        let isUpdateFirstNodeList = nodeType === this.currentData.FirstNodeType
        this.backCurrentNode({nodeType: nodeType, data: this.nodeInitObj[nodeType].data, component: this.nodeInitObj[nodeType].component, width: this.nodeInitObj[nodeType].width, operationType: 'add', nodeName: nodeName, isUpdateFirstNodeList: isUpdateFirstNodeList})
      },
      firstTypeChange () {
        this.currentData.FirstNode = ''
        this.getFirstNode(this.currentPBX)
      },
      firstNodeChange (isupdateFirstNode) {
        // isupdateFirstNode 是否需要更新节点列表
        let currentPBX = this.currentData.PBX || this.currentPBX
        if (isupdateFirstNode) {
          this.getFirstNode(currentPBX)
        }
        this.processChart(currentPBX)
      },
      handlerNodeClick (nodeStr) {
        let nodeAlias = nodeStr.substring(0, 1)
        let exten = ''
        let ivr = this.$store.state.session.ivrMap
        let currentPBX = this.currentPBX
        if (nodeAlias === 'O') {
          exten = '2'
        } else {
          exten = nodeStr.substring(2)
        }
        let nodeType = this.aliasNodeType[nodeAlias].type
        let currWidth = this.aliasNodeType[nodeAlias].width
        let currComponent = this.aliasNodeType[nodeAlias].component
        let ivrData = ivr[currentPBX].data
        let nodeName = this.nodeName2ChineseName[nodeType]
        // let _id = ''
        let currentData = {}
        for (var i in ivrData[nodeType]) {
          if (exten === ivrData[nodeType][i].Exten) {
            // _id = ivrData[nodeType][i]._id
            currentData = ivrData[nodeType][i]
            break
          }
        }
        this.backCurrentNode({nodeType: nodeType, data: currentData, component: currComponent, width: currWidth, operationType: 'update', nodeName: nodeName})
      },
      enlarge () {
        let dragObj = {textCode: this.textCode, name: 'IVR流程图', open: true, processId: 'process-flow__viewpop'}
        this.$store.commit('SET_BING_CALL_PROCESS', dragObj)
      },
      /**
       * 修改节点选择列表
       * currentData.FirstNodeType
       */
      getFirstNode (currentPbx) {
        let ivrObj = this.$store.state.session.ivrMap[currentPbx]
        let ivrData = {}
        if (ivrObj) {
          ivrData = ivrObj.data
        }
        if (ivrData) {
          let toPeerArr = ivrData[this.currentData.FirstNodeType]
          if (!this.currentData.FirstNodeType || this.currentData.FirstNodeType === 'system') {
            this.FirstNodeArr = toPeerArr
            this.showSelect = 'system'
          } else {
            if (toPeerArr) {
              this.FirstNodeArr = toPeerArr
              if (this.currentData.FirstNodeType === 'account_user') {
                this.showSelect = 'agent'
              } else {
                this.showSelect = 'others'
              }
            }
          }
        }
      },
      processChart (currentPbx) {
        let ivrObj = this.$store.state.session.ivrMap[currentPbx]
        let nodeType = this.currentData.FirstNodeType
        let nodeExten = this.currentData.FirstNode
        let ivr = {}
        if (ivrObj) {
          ivr = ivrObj.data
        } else {
          return
        }
        // this.getFirstNode(currentPbx)
        for (let i in ivr.vars) {
          this.vars[ivr.vars[i].VarName] = ivr.vars[i].Memo
        }
        if (nodeType === 'system' && nodeExten === '2') {
          nodeType = 'ivr_node_system'
        }
        let nodeArr = []
        let nodeObj = {}
        nodeObj.nodeType = nodeType
        nodeObj.nodeExten = nodeExten
        nodeArr.push(nodeObj)
        let existNodeArr = []
        this.textCode = ''
        this.textLength = 0
        this.ccount = 0
        this.processNode(currentPbx, nodeArr, existNodeArr, true)
        let mermaidholder = document.getElementById('process-flow__view')
        if (mermaidholder && mermaidholder.firstChild) {
          mermaidholder.removeChild(mermaidholder.firstChild)
        }
        let mermaidnode = document.createElement('div')
        mermaidnode.className = 'mermaid'
        mermaidnode.appendChild(document.createTextNode(this.textCode))
        mermaidholder.appendChild(mermaidnode)
        mermaid.flowchart = {
          useMaxWidth: true
        }
        mermaid.init()
        let nodeArray = document.querySelectorAll('#process-flow__view g.nodes g.node')
        let svg = document.querySelectorAll('#process-flow__view svg')[0]
        svg.style.maxWidth = '100%'
        svg.style.maxHeight = this.ccount * 50 + 150 + 'px'
        if (nodeArray.length <= 0) {
          this.chartError = true
        } else {
          nodeArray.forEach((item) => {
            item.addEventListener('click', window.nodeClick, false)
          })
          this.chartError = false
        }
      },
      /**
       *递归生成IVR流程图文本串
       * @param {String} 当前pbx
       * @param {Object} nodes 当前节点信息
       * @param {Array}
       * @param {Boolean} 是否是开始节点
       */
      processNode (currentPbx, nodes, existNodeArr, isStartNode, preNodeCode) {
        this.ccount ++
        let ivrObj = this.$store.state.session.ivrMap[currentPbx]
        let ivr = {}
        if (ivrObj) {
          ivr = ivrObj.data
        }
        for (let key in nodes) {
          let nodeType = nodes[key].nodeType
          let nodeExten = nodes[key].nodeExten
          if (nodeType && nodeExten) {
            if (nodeType === 'system' && nodeExten === '2') {
              nodeType = 'ivr_node_system'
            }
            let peerCondition = ''
            if (nodes[key].peerCondition) {
              peerCondition = nodes[key].peerCondition === 'next' ? '' : '--' + nodes[key].peerCondition
            }
            let nodeAlias = ''
            let nodeName = ''
            let nodeCode = ''
            let nodeFont = ''
            let unicodeName = ''
            let currentNode = null
            let nextNodeArr = []
            if (nodeType === 'system') {
              nodeAlias = this.nodeName2Alias[nodeType][nodeExten]
              nodeFont = this.nodeType2Font[nodeType][nodeExten]
            } else {
              nodeAlias = this.nodeName2Alias[nodeType]
              nodeFont = this.nodeType2Font[nodeType]
            }
            if (isStartNode) {
              existNodeArr.push(nodeAlias + ':' + nodeExten)
              if (nodeType === 'account_user') {
                for (let i in ivr[nodeType]) {
                  if (nodeExten === ivr[nodeType][i]._id) {
                    currentNode = ivr[nodeType][i]
                    nodeExten = currentNode.exten
                    nodeName = currentNode.displayName
                    if (nodeName.length > 5) {
                      for (let x = 0; x < 5; x++) {
                        unicodeName += '&#' + nodeName.charCodeAt(x)
                      }
                      nodeName = unicodeName + '..'
                    } else {
                      for (let y = 0; y < nodeName.length; y++) {
                        unicodeName += '&#' + nodeName.charCodeAt(y)
                      }
                      nodeName = unicodeName
                    }
                    break
                  }
                }
                if (currentNode) {
                  nodeCode = nodeAlias + '-' + nodeExten
                  // this.textCode += 'graph LR\n' + nodeCode + '((' + nodeFont + ' ' + nodeName + '))\n'
                  this.textCode += 'graph LR\n' + nodeCode + '(' + nodeFont + ' ' + nodeName + ')\n'
                  this.textLength ++
                }
              } else {
                for (let i in ivr[nodeType]) {
                  if (nodeExten === ivr[nodeType][i].Exten) {
                    currentNode = ivr[nodeType][i]
                    nodeName = currentNode.DisplayName
                    break
                  }
                }
                if (currentNode) {
                  if (nodeType === 'ivr_node_system') {
                    nodeName = '拨打工号'
                  }
                  if (nodeName.length > 5) {
                    for (let x = 0; x < 5; x++) {
                      unicodeName += '&#' + nodeName.charCodeAt(x)
                    }
                    nodeName = unicodeName + '..'
                  } else {
                    for (let y = 0; y < nodeName.length; y++) {
                      unicodeName += '&#' + nodeName.charCodeAt(y)
                    }
                    nodeName = unicodeName
                  }
                  nodeCode = nodeAlias + '-' + nodeExten
                  this.textCode += 'graph LR\n' + nodeCode + '(' + nodeFont + ' ' + nodeName + ')\n'
                  this.textLength ++

                  if (nodeType === 'ivr_node_system') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerTypeWhenEmpnoNotExist
                    nextNodeObj.nodeExten = currentNode.ToPeerWhenEmpnoNotExist
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoNotExist
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenEmpnoAgentBusy
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenEmpnoAgentBusy
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoAgentBusy
                    let nextNodeObj2 = {}
                    nextNodeObj2.nodeType = currentNode.ToPeerTypeWhenEmpnoLogoff
                    nextNodeObj2.nodeExten = currentNode.ToPeerWhenEmpnoLogoff
                    nextNodeObj2.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoLogoff
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    nextNodeArr.push(nextNodeObj2)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_announcement' || nodeType === 'ivr_node_text_announcement' ||
                          nodeType === 'ivr_node_assignment' || nodeType === 'ivr_node_voice_mail') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerType
                    nextNodeObj.nodeExten = currentNode.ToPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType]
                    nextNodeArr.push(nextNodeObj)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_encrypt_md5' || nodeType === 'ivr_node_satisfaction' ||
                          nodeType === 'ivr_node_ivr_menu' || nodeType === 'ivr_node_asr') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.NextPeerType
                    nextNodeObj.nodeExten = currentNode.NextPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType]
                    nextNodeArr.push(nextNodeObj)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_validation') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerType
                    nextNodeObj.nodeExten = currentNode.ToPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerType
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenWaitTimeout
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenWaitTimeout
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenWaitTimeout
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_call_url') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.NextPeerType
                    nextNodeObj.nodeExten = currentNode.NextPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].NextPeerType
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenTimeout
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenTimeout
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenTimeout
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_ivr') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n' + ' class ' + nodeCode + ' ' + nodeType + '\n '
                    this.textCode += nodeCode + '-->' + nodeAlias + '-' + 'V' + '-' + nodeExten + '{按键}\n' + ' class ' + nodeAlias + '-' + 'V' + '-' + nodeExten + ' gray\n'
                    nodeCode = nodeAlias + '-' + 'V' + '-' + nodeExten
                    existNodeArr.push(nodeCode)
                    for (let j in currentNode.IvrKeys) {
                      let nextNodeObj = {}
                      nextNodeObj.nodeType = currentNode.IvrKeys[j].ToPeerType
                      nextNodeObj.nodeExten = currentNode.IvrKeys[j].ToPeer
                      nextNodeObj.peerCondition = currentNode.IvrKeys[j].Key
                      nextNodeArr.push(nextNodeObj)
                    }
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_route') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let validateText = '变量路由'
                    this.textCode += nodeCode + '-->' + nodeAlias + '-' + 'V' + '-' + nodeExten + '{' + validateText + '}\n'
                    nodeCode = nodeAlias + '-' + 'V' + '-' + nodeExten
                    existNodeArr.push(nodeCode)
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerType
                    nextNodeObj.nodeExten = currentNode.ToPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerType
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeUnmatched
                    nextNodeObj1.nodeExten = currentNode.ToPeerUnmatched
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeUnmatched
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_date') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let validateText = '判断时间条件'
                    this.textCode += nodeCode + '-->' + nodeAlias + '-' + 'V' + '-' + nodeExten + '{' + validateText + '}\n'
                    nodeCode = nodeAlias + '-' + 'V' + '-' + nodeExten
                    existNodeArr.push(nodeCode)
                    let dates = currentNode.Dates
                    if (dates != null && dates.length > 0) {
                      for (let key in dates) {
                        let date = dates[key]
                        let nextNodeObj = {}
                        nextNodeObj.nodeType = date.NextPeerType
                        nextNodeObj.nodeExten = date.NextPeer
                        let peerCondition = this.node2PeerCondition[nodeType].Order + '  ' + date.Order
                        nextNodeObj.peerCondition = peerCondition
                        nextNodeArr.push(nextNodeObj)
                      }
                    }
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.NextPeerUnmatchType
                    nextNodeObj1.nodeExten = currentNode.NextPeerUnmatch
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].NextPeerUnmatch
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_superDialJobNum') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerTypeWhenFrontOffice
                    nextNodeObj.nodeExten = currentNode.ToPeerWhenFrontOffice
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenFrontOffice
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenEmpnoNotExist
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenEmpnoNotExist
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoNotExist
                    let nextNodeObj2 = {}
                    nextNodeObj2.nodeType = currentNode.ToPeerTypeWhenEmpnoAgentBusy
                    nextNodeObj2.nodeExten = currentNode.ToPeerWhenEmpnoAgentBusy
                    nextNodeObj2.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoAgentBusy
                    let nextNodeObj3 = {}
                    nextNodeObj3.nodeType = currentNode.ToPeerTypeWhenEmpnoLogoff
                    nextNodeObj3.nodeExten = currentNode.ToPeerWhenEmpnoLogoff
                    nextNodeObj3.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoLogoff
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    nextNodeArr.push(nextNodeObj2)
                    nextNodeArr.push(nextNodeObj3)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_queue') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerTypeWhenQueueEmpty
                    nextNodeObj.nodeExten = currentNode.ToPeerWhenQueueEmpty
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenQueueEmpty
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenWait
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenWait
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenWait
                    let nextNodeObj2 = {}
                    nextNodeObj2.nodeType = currentNode.ToPeerTypeWhenWaitTimeout
                    nextNodeObj2.nodeExten = currentNode.ToPeerWhenWaitTimeout
                    nextNodeObj2.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenWaitTimeout
                    let nextNodeObj3 = {}
                    nextNodeObj3.nodeType = currentNode.ToPeerTypeWhenHanguped
                    nextNodeObj3.nodeExten = currentNode.ToPeerWhenHanguped
                    nextNodeObj3.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenHanguped
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    nextNodeArr.push(nextNodeObj2)
                    nextNodeArr.push(nextNodeObj3)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_room' || nodeType === 'ivr_node_extension_peer' || nodeType === 'ivr_node_twowaycall') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                  }
                }
              }
            } else if (existNodeArr.indexOf(nodeAlias + ':' + nodeExten) === -1) {
              existNodeArr.push(nodeAlias + ':' + nodeExten)
              if (nodeType === 'account_user') {
                for (let i in ivr[nodeType]) {
                  if (nodeExten === ivr[nodeType][i]._id) {
                    currentNode = ivr[nodeType][i]
                    nodeExten = currentNode.exten
                    nodeName = currentNode.displayName
                    if (nodeName.length > 5) {
                      for (let x = 0; x < 5; x++) {
                        unicodeName += '&#' + nodeName.charCodeAt(x)
                      }
                      nodeName = unicodeName + '..'
                    } else {
                      for (let y = 0; y < nodeName.length; y++) {
                        unicodeName += '&#' + nodeName.charCodeAt(y)
                      }
                      nodeName = unicodeName
                    }
                    break
                  }
                }
                if (currentNode) {
                  nodeCode = nodeAlias + '-' + nodeExten
                  this.textCode += preNodeCode + peerCondition + '-->' + nodeCode + '(' + nodeFont + ' ' + nodeName + ')\n'
                  this.textLength ++
                }
              } else {
                for (let i in ivr[nodeType]) {
                  if (nodeExten === ivr[nodeType][i].Exten) {
                    currentNode = ivr[nodeType][i]
                    nodeName = currentNode.DisplayName
                    break
                  }
                }
                if (currentNode) {
                  if (nodeType === 'ivr_node_system') {
                    nodeName = '拨打工号'
                  }
                  if (nodeName.length > 5) {
                    for (let x = 0; x < 5; x++) {
                      unicodeName += '&#' + nodeName.charCodeAt(x)
                    }
                    nodeName = unicodeName + '..'
                  } else {
                    for (let y = 0; y < nodeName.length; y++) {
                      unicodeName += '&#' + nodeName.charCodeAt(y)
                    }
                    nodeName = unicodeName
                  }
                  nodeCode = nodeAlias + '-' + nodeExten
                  if (nodeType === 'ivr_node_queue') {
                    this.textCode += preNodeCode + peerCondition + '-->' + nodeCode + '(' + nodeFont + ' ' + nodeName + ')\n'
                  } else {
                    this.textCode += preNodeCode + peerCondition + '-->' + nodeCode + '[' + nodeFont + ' ' + nodeName + ']\n'
                  }
                  this.textLength ++
                  if (nodeType === 'ivr_node_system') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerTypeWhenEmpnoNotExist
                    nextNodeObj.nodeExten = currentNode.ToPeerWhenEmpnoNotExist
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoNotExist
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenEmpnoAgentBusy
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenEmpnoAgentBusy
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoAgentBusy
                    let nextNodeObj2 = {}
                    nextNodeObj2.nodeType = currentNode.ToPeerTypeWhenEmpnoLogoff
                    nextNodeObj2.nodeExten = currentNode.ToPeerWhenEmpnoLogoff
                    nextNodeObj2.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoLogoff
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    nextNodeArr.push(nextNodeObj2)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_announcement' || nodeType === 'ivr_node_text_announcement' ||
                          nodeType === 'ivr_node_assignment' || nodeType === 'ivr_node_voice_mail') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerType
                    nextNodeObj.nodeExten = currentNode.ToPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType]
                    nextNodeArr.push(nextNodeObj)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_encrypt_md5' || nodeType === 'ivr_node_satisfaction' ||
                          nodeType === 'ivr_node_ivr_menu' || nodeType === 'ivr_node_asr') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.NextPeerType
                    nextNodeObj.nodeExten = currentNode.NextPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType]
                    nextNodeArr.push(nextNodeObj)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_validation') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerType
                    nextNodeObj.nodeExten = currentNode.ToPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerType
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenWaitTimeout
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenWaitTimeout
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenWaitTimeout
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_call_url') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.NextPeerType
                    nextNodeObj.nodeExten = currentNode.NextPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].NextPeerType
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenTimeout
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenTimeout
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenTimeout
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_ivr') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    this.textCode += nodeCode + '-->' + nodeAlias + '-' + 'V' + '-' + nodeExten + '{按键}\n'
                    nodeCode = nodeAlias + '-' + 'V' + '-' + nodeExten
                    existNodeArr.push(nodeCode)
                    for (let j in currentNode.IvrKeys) {
                      let nextNodeObj = {}
                      nextNodeObj.nodeType = currentNode.IvrKeys[j].ToPeerType
                      nextNodeObj.nodeExten = currentNode.IvrKeys[j].ToPeer
                      nextNodeObj.peerCondition = currentNode.IvrKeys[j].Key
                      nextNodeArr.push(nextNodeObj)
                    }
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_route') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let validateText = '变量路由'
                    this.textCode += nodeCode + '-->' + nodeAlias + '-' + 'V' + '-' + nodeExten + '{' + validateText + '}\n'
                    nodeCode = nodeAlias + '-' + 'V' + '-' + nodeExten
                    existNodeArr.push(nodeCode)
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerType
                    nextNodeObj.nodeExten = currentNode.ToPeer
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerType
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeUnmatched
                    nextNodeObj1.nodeExten = currentNode.ToPeerUnmatched
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeUnmatched
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_date') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    existNodeArr.push(nodeCode)
                    let validateText = '判断时间条件'
                    this.textCode += nodeCode + '-->' + nodeAlias + '-' + 'V' + '-' + nodeExten + '{' + validateText + '}\n'
                    nodeCode = nodeAlias + '-' + 'V' + '-' + nodeExten
                    existNodeArr.push(nodeCode)
                    let dates = currentNode.Dates
                    if (dates != null && dates.length > 0) {
                      for (let key in dates) {
                        let date = dates[key]
                        let nextNodeObj = {}
                        nextNodeObj.nodeType = date.NextPeerType
                        nextNodeObj.nodeExten = date.NextPeer
                        let peerCondition = this.node2PeerCondition[nodeType].Order + '  ' + date.Order
                        nextNodeObj.peerCondition = peerCondition
                        nextNodeArr.push(nextNodeObj)
                      }
                    }
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.NextPeerUnmatchType
                    nextNodeObj1.nodeExten = currentNode.NextPeerUnmatch
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].NextPeerUnmatch
                    nextNodeArr.push(nextNodeObj1)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_superDialJobNum') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerTypeWhenFrontOffice
                    nextNodeObj.nodeExten = currentNode.ToPeerWhenFrontOffice
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenFrontOffice
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenEmpnoNotExist
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenEmpnoNotExist
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoNotExist
                    let nextNodeObj2 = {}
                    nextNodeObj2.nodeType = currentNode.ToPeerTypeWhenEmpnoAgentBusy
                    nextNodeObj2.nodeExten = currentNode.ToPeerWhenEmpnoAgentBusy
                    nextNodeObj2.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoAgentBusy
                    let nextNodeObj3 = {}
                    nextNodeObj3.nodeType = currentNode.ToPeerTypeWhenEmpnoLogoff
                    nextNodeObj3.nodeExten = currentNode.ToPeerWhenEmpnoLogoff
                    nextNodeObj3.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenEmpnoLogoff
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    nextNodeArr.push(nextNodeObj2)
                    nextNodeArr.push(nextNodeObj3)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_queue') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                    let nextNodeObj = {}
                    nextNodeObj.nodeType = currentNode.ToPeerTypeWhenQueueEmpty
                    nextNodeObj.nodeExten = currentNode.ToPeerWhenQueueEmpty
                    nextNodeObj.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenQueueEmpty
                    let nextNodeObj1 = {}
                    nextNodeObj1.nodeType = currentNode.ToPeerTypeWhenWait
                    nextNodeObj1.nodeExten = currentNode.ToPeerWhenWait
                    nextNodeObj1.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenWait
                    let nextNodeObj2 = {}
                    nextNodeObj2.nodeType = currentNode.ToPeerTypeWhenWaitTimeout
                    nextNodeObj2.nodeExten = currentNode.ToPeerWhenWaitTimeout
                    nextNodeObj2.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenWaitTimeout
                    let nextNodeObj3 = {}
                    nextNodeObj3.nodeType = currentNode.ToPeerTypeWhenHanguped
                    nextNodeObj3.nodeExten = currentNode.ToPeerWhenHanguped
                    nextNodeObj3.peerCondition = this.node2PeerCondition[nodeType].ToPeerTypeWhenHanguped
                    nextNodeArr.push(nextNodeObj)
                    nextNodeArr.push(nextNodeObj1)
                    nextNodeArr.push(nextNodeObj2)
                    nextNodeArr.push(nextNodeObj3)
                    this.processNode(currentPbx, nextNodeArr, existNodeArr, false, nodeCode)
                  } else if (nodeType === 'ivr_node_room' || nodeType === 'ivr_node_extension_peer' || nodeType === 'ivr_node_twowaycall') {
                    this.textCode += 'click ' + nodeCode + ' nodeClick ' +
                            '"' + this.nodeName2ChineseName[nodeType] + '"\n'
                  }
                }
              }
            } else {
              if (nodeType === 'account_user') {
                for (let i in ivr[nodeType]) {
                  if (nodeExten === ivr[nodeType][i]._id) {
                    currentNode = ivr[nodeType][i]
                    nodeExten = currentNode.exten
                    break
                  }
                }
                if (currentNode) {
                  nodeCode = nodeAlias + '-' + nodeExten
                  this.textCode += preNodeCode + peerCondition + '-->' + nodeCode + '\n'
                  this.textLength ++
                }
              } else {
                for (let i in ivr[nodeType]) {
                  if (nodeExten === ivr[nodeType][i].Exten) {
                    currentNode = ivr[nodeType][i]
                    break
                  }
                }
                if (currentNode) {
                  nodeCode = nodeAlias + '-' + nodeExten
                  this.textCode += preNodeCode + peerCondition + '-->' + nodeCode + '\n'
                  this.textLength ++
                }
              }
            }
          }
        }
      },
      backCurrentNode (data) {
        this.$emit('backCurrentNode', data)
      },
      prcessNodeSaveClick () {},
      prcessNodeCancleClick () {},
      prcessNodeSave () {
        let data = {}
        let message = 'IVR流程添加成功！'
        let actionType = 'saveIvrProcess'
        let currentData = this.currentData
        if (currentData.DisplayName && currentData.FirstNodeType && currentData.FirstNode) {
          if (currentData._id) {
            data._id = currentData._id
            actionType = 'updateIvrProcess'
            message = 'IVR流程更新成功！'
          }
          data.DisplayName = currentData.DisplayName
          data.FirstNodeType = currentData.FirstNodeType
          data.FirstNode = currentData.FirstNode
          data.Account = currentData.Account || this.$store.state.session.account.account
          data.PBX = currentData.PBX || this.currentPBX
          this.$store.dispatch(actionType, data).then(res => {
            this.$message({
              type: 'success',
              message: message
            })
            this.$emit('processUpdateSuccess')
          })
        } else {
          this.$message({
            type: 'error',
            message: '流程名称必填!'
          })
        }
      },
      prcessNodeCancel () {
        this.$emit('prcessNodeCancel')
      },
      active () {
        let obj = {}
        obj.PBX = this.currentPBX
        obj.Account = this.$store.state.session.account.account
        this.$store.dispatch('reloadIvr', obj).then(res => {
          if (res.success) {
            this.toolsDisable = true
            this.$message({
              type: 'success',
              message: this.$t('configLazyLoad.process.effectiveSuccessfully')
            })
          }
        })
      }
    },
    watch: {
      flowData (newData) {
        this.currentData = deepClone(newData)
        this.firstNodeChange(true)
      },
      currentPBX () {
        let routerName = this.$route.meta.title
        let comName = this.name
        if (routerName === comName) {}
      },
      isUpdateFirstNode () {
        // 是否强制更新 节点列表
        this.getFirstNode(this.currentPBX)
      },
      isUpdateProcessView () {
        // 是否强制更新流程图
        if (this.currentData) {
          this.firstNodeChange()
        }
        this.toolsDisable = false
      },
      processViewShow (newView) {
        if (newView) {
          console.log(this.currentData)
          console.log(this.flowData)
        }
      }
    },
    beforeMount () {
      this.currentData = deepClone(this.flowData)
      this.firstNodeChange(true)
    }
  }
</script>
<style lang="stylus">
  @import "../../../../../assets/common.styl"
 #process-flow
  .process-flow__title
    position relative
    margin-top 38px
    border-top 2px dotted #ccc
    padding-top 26px
    .primary_btn
      height 34px
    .el-dropdown
      margin-right 20px
    .process-flow-title__text
      position absolute
      background white
      height 20px
      line-height 20px
      top -10px
      left 18px
      font-size 14px
    .process-flow-title__text:before
      content ''
      display block
      position absolute
      width 14px
      height 14px
      background #ccc
      top 0
      bottom 0
      margin auto 0
      left -18px
  .process-flow__operation
    > div
      margin-right 40px
      box-sizing border-box
    display flex
    flex-wrap nowrap
    align-items bottom
    .process-poeration__btn
      display flex
      align-items flex-end
      button
       height 30px
      .save_btn
        background #FF9910
        color white
        border 1px solid #FF9910
        padding 0 10px 0
        font-size 12px
    .process-poeration__start > div
      display flex
      align-items center
      > span
       margin 0 10px 0
      .el-input__inner
        padding-right 10px
        .el-input__suffix
          margin-right 0
        .el-input__suffix-inner
          margin-right 0
  .detail-wrap
     .label-text
      display inline-block
      margin 0 0 8px
     .icon-group
       background #F6F6F6
       color #3B5998
       border-radius 2px
       padding 20px
       line-height 2
       display flex
       flex-wrap wrap
       span
        display block
        width 20%
     #process-flow__view
       .edgeLabel
        background white
        color #595959
       .gray
        foreignObject
         color #424242
       path
        stroke #8BBBE8
       marker
        fill #8BBBE8
       min-height 50px
       rect
         fill #C8E2FA
         stroke #C8E2FA
         stroke-width 2px
       foreignObject
         color #459AE9
       polygon
         fill #E0E0E0
         stroke #E0E0E0
         stroke-width 2px
       .ivr_node_ivr > circle,
       .ivr_node_ivr > rect
         fill #C8E2FA
         stroke #C8E2FA
         stroke-width 2px
     .error
       font-size 12px
       height 60px
       line-height 60px
</style>
